home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / arts / common.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  3.3 KB  |  142 lines

  1.     /*
  2.  
  3.     Copyright (C) 2000 Stefan Westerfeld
  4.                        stefan@space.twc.de
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.   
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.    
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.     Boston, MA 02111-1307, USA.
  20.  
  21.     */
  22.  
  23. #ifndef COMMON_H
  24. #define COMMON_H
  25.  
  26. #include "buffer.h"
  27. #include "type.h"
  28. #include "dispatcher.h"
  29. #include "object.h"
  30. #include "connection.h"
  31. #include "objectmanager.h"
  32. #include "idlfilereg.h"
  33. #include "asyncstream.h"
  34. #include "mcoputils.h"
  35. #include "anyref.h"
  36. #include "connect.h"
  37.  
  38. /*
  39.  * BC - Status (2002-03-08): Read/WriteObject(Seq)
  40.  *
  41.  * Will be kept binary compatible by NOT TOUCHING AT ALL. Do not change this.
  42.  * (Interaction with generated code).
  43.  */
  44.  
  45. /* define this to see what mcop transfers around */
  46. #undef DEBUG_IO
  47.  
  48. /* define this to see what mcop messages are processed */
  49. #undef DEBUG_MESSAGES
  50.  
  51. #include "core.h"
  52.  
  53. namespace Arts {
  54. /* some marshalling helpers */
  55.  
  56. template<class T>
  57. void readTypeSeq(Buffer& stream, std::vector<T>& sequence) {
  58.     sequence.clear();
  59.  
  60.     unsigned long l = stream.readLong();
  61.     while(l--) sequence.push_back(T(stream));
  62. }
  63.  
  64. template<class T>
  65. void writeTypeSeq(Buffer& stream, const std::vector<T>& sequence) {
  66.     stream.writeLong(sequence.size());
  67.     for(unsigned long l=0;l<sequence.size();l++)
  68.         sequence[l].writeType(stream);
  69. }
  70.  
  71. template<class T>
  72. void writeObject(Buffer& stream, T* object) {
  73.     if(object)
  74.     {
  75.         /*
  76.           * perhaps reimplement directly (without conversion to/from string)
  77.           * for more speed
  78.           */
  79.  
  80.         std::string s = object->_toString();
  81.  
  82.         Buffer buffer;
  83.         buffer.fromString(s,"MCOP-Object");
  84.         ObjectReference reference(buffer);
  85.  
  86.         object->_copyRemote();    // prevents that the object is freed for a while
  87.         reference.writeType(stream);
  88.     }
  89.     else
  90.     {
  91.         ObjectReference null_reference;
  92.  
  93.         null_reference.serverID = "null";
  94.         null_reference.objectID = 0;
  95.         null_reference.writeType(stream);
  96.     }
  97. }
  98.  
  99. template<class T>
  100. void readObject(Buffer& stream, T*& result) {
  101.     ObjectReference reference(stream);
  102.  
  103.     if(reference.serverID == "null")
  104.         result = 0;        // null reference?
  105.     else
  106.         result = T::_fromReference(reference,false);
  107. }
  108.  
  109. template<class T>
  110. void readObjectSeq(Buffer& stream, std::vector<T>& sequence)
  111. {
  112.     sequence.clear();
  113.  
  114.     unsigned long l = stream.readLong();
  115.     while(l--)
  116.     {
  117.         typename T::_base_class *temp;
  118.         readObject(stream, temp);
  119.         sequence.push_back(T::_from_base(temp));
  120.     }
  121. }
  122.  
  123. template<class T>
  124. void writeObjectSeq(Buffer& stream, const std::vector<T>& sequence)
  125. {
  126.     stream.writeLong(sequence.size());
  127.  
  128.     for(unsigned long l=0;l<sequence.size();l++)
  129.     {
  130.         T object = sequence[l];
  131.         writeObject(stream,object._base());
  132.     }
  133. }
  134.  
  135. #ifndef MCOPBYTE_DEFINED
  136. #define MCOPBYTE_DEFINED
  137. typedef unsigned char mcopbyte;
  138. #endif
  139.  
  140. }
  141. #endif
  142.